import {BaseSeqCommand} from "../../../v-cairn/BaseSeqCommand.ts";
import {LoginEvent} from "../LoginEvent.ts";
import {useLoginStore} from "../LoginStore.ts";
import {VCairnEvent} from "v-cairn";

export class LoginCommand extends BaseSeqCommand {
    constructor() {
        super();
        this.nextEvents = [
            new VCairnEvent(LoginEvent.GET_USER_INFO_1, 1),
            new VCairnEvent(LoginEvent.GET_USER_INFO_2, 2)
        ];
    }

    execute() {
        const { formData } = useLoginStore();
        const userName = formData.userName;
        const password = formData.password;
        this.service.send({
            url: '/login',
            method: 'post',
            data: {
                userName, password
            }
        });
    }

    protected onSuccess() {
        this.executeNextCommands();
    }

    onFinally() {
        super.onFinally();
        console.log('finally');
        this.executeNextCommands();
    }

}